package com.hkw.servlet;

import com.hkw.model.ClassRoom;
import com.hkw.service.IClassRoomService;
import com.hkw.service.impl.ClassRoomServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 查找教师Servlet
 */
@WebServlet(name = "FindClassRoomServlet",urlPatterns = "/findClassRoom")
public class FindClassRoomServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        IClassRoomService classRoomService = new ClassRoomServiceImpl();
        ClassRoom classRoom = classRoomService.findClassRoomById(Integer.parseInt(id));
        if(classRoom != null){
            request.setAttribute("classroom",classRoom);
            request.getRequestDispatcher("classRoomUpdate.jsp").forward(request,response);
        }else{
            response.sendRedirect("classRoomList");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
